package com.mostromas.ess.product.controller;

import com.mostromas.ess.entities.ExecutiveStandards;
import com.mostromas.ess.entities.ProductBrand;
import com.mostromas.ess.product.service.IProductBrandService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌表-前端控制器
 */
@Api(value = "品牌管理接口",description = "品牌管理接口，提供品牌的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/brand")
public class ProductBrandController {

    @Autowired
    private IProductBrandService productBrandService;

    @PreAuthorize(("hasAuthority('brand:search')"))
    @ApiOperation("获取所有的品牌信息接口")
    @GetMapping("/list")
    public Result list(){
        return Result.ok(productBrandService.list());
    }

    @PreAuthorize(("hasAuthority('brand:search')"))
    @ApiOperation("查询品牌详情接口")
    @ApiImplicitParam(name = "id",value = "品牌ID",required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable("id") String id){
        ProductBrand brand = productBrandService.getById(id);
        return Result.ok(brand);
    }

    @PreAuthorize(("hasAuthority('brand:edit')"))
    @ApiOperation("修改品牌信息接口")
    @PutMapping
    public Result update(@RequestBody ProductBrand brand){
        productBrandService.updateById(brand);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('brand:add')"))
    @ApiOperation("新增品牌信息接口")
    @PostMapping
    public Result save(@RequestBody ProductBrand brand){
        productBrandService.save(brand);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('brand:delete')"))
    @ApiOperation("删除品牌信息接口")
    @ApiImplicitParam(name = "id",value = "品牌ID",required = true)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        productBrandService.removeById(id);
        return Result.ok();
    }
}
